package easy;

public class Solution_2016 {

    public int maximumDifference(int[] nums) {
        int[] array = new int[nums.length];
        array[0] = nums[0];
        for (int i = 1; i < nums.length; i++) {
            array[i] = Math.min(array[i - 1], nums[i]);
        }
        int sub = -1;
        for (int i = 1; i < array.length; i++) {
            int temp = nums[i] - array[i - 1];
            if (temp > 0 && (sub == -1 || temp > sub)) {
                sub = temp;
            }
        }
        return sub;
    }

    public static void main(String[] args) {
        Solution_2016 model = new Solution_2016();
        System.out.println(model.maximumDifference(new int[]{7, 1, 5, 4}));
        System.out.println(model.maximumDifference(new int[]{9, 4, 3, 2}));
        System.out.println(model.maximumDifference(new int[]{1, 5, 2, 10}));
    }
}
